package com.concerneyes.pay;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.concerneyes.R;
import com.concerneyes.glasses.task.GlassesListener;
import com.concerneyes.health.HealthAddUserActivity;
import com.concerneyes.mine.Task.GlassManImpl;
import com.concerneyes.mine.Task.GlassManListener;
import com.concerneyes.mine.model.MyGlassManModel;
import com.concerneyes.pay.adapter.ChooseGlassesManAdapter;

import java.util.List;

import common.AbsActivity;
import util.ActivityUtil;

/**
 * 选择配镜人
 */

public class ChooseGlassesManActivity extends AbsActivity implements GlassManListener,AdapterView.OnItemClickListener {
    private ListView lv_my_adress;
    private ChooseGlassesManAdapter adapter;
    private GlassManImpl impl;

    @Override
    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(R.layout.activity_choose_glassesman);
        setTitle(R.string.choose_glasses_man);
        initView();
    }

    private void initView() {
        lv_my_adress = (ListView) findViewById(R.id.lv_my_adress);

        View footerView = LayoutInflater.from(this).inflate(R.layout.item_list_me, null);
        View view_diver = footerView.findViewById(R.id.view_diver);
        RelativeLayout rl_item = (RelativeLayout) footerView.findViewById(R.id.rl_item);
        TextView tv_me_title = (TextView) footerView.findViewById(R.id.tv_me_title);
        tv_me_title.setText(R.string.add_glass_man);
        rl_item.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Bundle bundle = new Bundle();
                bundle.putBoolean("isAdd", true);
                ActivityUtil.setIntent(ChooseGlassesManActivity.this, AddNewGlassesMan.class, bundle);

            }
        });
        view_diver.setVisibility(View.VISIBLE);

        lv_my_adress.addFooterView(footerView);
        adapter = new ChooseGlassesManAdapter(this);
        lv_my_adress.setAdapter(adapter);
        lv_my_adress.setOnItemClickListener(this);
        impl = new GlassManImpl(this, this);
        impl.listGlassMan();
    }

    @Override
    protected void onResume() {
        super.onResume();
        impl.listGlassMan();
    }

    @Override
    public void glassManListSuccess(List<MyGlassManModel> model) {
        adapter.clear();
        adapter.addItems(model);
    }

    @Override
    public void glassManListFail() {

    }

    @Override
    public void deleteGlassManSuccess(List<MyGlassManModel> model) {

    }

    @Override
    public void deleteGlassManFail() {

    }

    @Override
    public void addGlassManSuccess() {

    }

    @Override
    public void addGlassManFail() {

    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        Intent intent = new Intent();
        Bundle bundle = new Bundle();
        bundle.putSerializable("MyGlassManModel",adapter.getItem(position));
        intent.putExtras(bundle);
        setResult(20, intent);
        finish();
    }
}
